import { defineStore } from 'pinia'
import { ref } from 'vue'
import { swiper, brick, show, show2, promo, banner } from '@/model/homeModel'
import { categoryOne } from '@/model/categoryModel'
import {
  searchSwiper,
  searchHome,
  searchShow,
  searchShow2,
  searchPromo,
  searchBanner,
  searchMenu
} from '@/api/home'

export default defineStore('home', () => {
  const swiper = ref<swiper[]>()

  const getSwiper = async () => {
    const result = await searchSwiper()
    if (result.status === 200) swiper.value = result.data
  }
  const brick = ref<brick[]>()
  const getHome = async () => {
    const result = await searchHome()
    if (result.status === 200) brick.value = result.data
  }
  const show = ref<show[]>([])
  const getShow = async (category_id: number) => {
    const result = await searchShow(category_id)
    if (result.status === 200) show.value = result.data
  }
  const show2 = ref<show2[]>([])
  const getShow2 = async (category_id: number) => {
    const result = await searchShow2(category_id)
    if (result.status === 200) show2.value = result.data
  }
  const promo = ref<promo[]>([])
  const getPromo = async () => {
    const result = await searchPromo()
    if (result.status === 200) promo.value = result.data
  }
  const banner = ref<banner[]>()
  const getBanner = async () => {
    const result = await searchBanner()
    if (result.status === 200) banner.value = result.data
  }
  const menu = ref<categoryOne[]>()
  const getMenu = async () => {
    const result = await searchMenu()
    if (result.status === 200) menu.value = result.data
  }
  return {
    swiper,
    getSwiper,
    brick,
    getHome,
    show,
    getShow,
    show2,
    getShow2,
    promo,
    getPromo,
    banner,
    getBanner,
    menu,
    getMenu
  }
})
